//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2007 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   CATEGORY_ITEM_LINE
// AUTHOR           :   Ray Guo 
// DATE CREATE      :   2007/05/24
// DESCRIPTION      :   a COMMON DAO file for the function, CATEGORY_ITEM_LINE
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2007/05/24   Ray Guo         1.0                 source is generated.
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package com.erp.app.catalogLogin.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.erp.app.catalogLogin.dao.CategoryItemLineCommonDao;
import com.erp.app.catalogLogin.bizLogic.CategoryItemLineCommonUtil;

import com.erp.app.common.ProjectConstants;
import com.erp.framework.model.criteria.SimpleBaseSrchCriteria;
import com.erp.framework.model.vo.SimpleBaseVo;
import com.erp.app.catalogLogin.criteria.CategoryItemLineSrchCriteria;

/**
* <p>A <strong>CommonDao</strong> provides database access functions
*  for delegate classes.
*
* @author          Ray Guo 
* @version 1.0     2007/05/24
* @since           FrameWork 1.1
*
*/
public class CategoryItemLineCommonDao {

	private CategoryItemLineCommonUtil util = new CategoryItemLineCommonUtil();

	/**
	* Returns the SQL select statement.
	* @param         obj     the searching criteria
	* @return        a string containing sql query
	*
	* @author     Ray Guo 
	* @since      Framework 1.1
	*/
	public static String getHdrSqlQuery(SimpleBaseSrchCriteria obj) {

		CategoryItemLineSrchCriteria criteria = (CategoryItemLineSrchCriteria) obj;
		String sql = "";
		String whereClause = hdrToWhereClause(criteria);
		String groupByClause = "";
		String orderByClause = "ORDER BY COMPANY_CODE, ITEM_LINE";

		if(!criteria.isSearchResult()){
			sql = "SELECT COMPANY_CODE, ITEM_LINE, ITEM_LINE_DESC, STATUS, DC_IND, "
			+ "DC_DATE, CREATE_USER, CREATE_DATE, UPDATE_USER, UPDATE_DATE, "
			+ "SHOW_IN_CATALOG "
			+ "FROM V_CATEGORY_ITEM_LINE "
			+ whereClause
			+ groupByClause
			+ orderByClause;
		} else {
			throw new RuntimeException("Please implement query for the search screen");
		}

		return sql;
	}

	/**
	* Sets the values of a result set to a vo for a search screen
	* @param         rs   the incoming result set
	* @return        a vo containing the result set values
	*
	* @author     Ray Guo 
	* @since      Framework 1.1
	*/
	public static SimpleBaseVo getHdrSearchResultSetValues(ResultSet rs) throws SQLException {

		throw new RuntimeException("Please get the ResultSet values for the search screen");

	}

	/**
	* Returns the where clause of a SQL select statement.
	* @param         obj     the searching criteria
	* @return        a string containing the where clause
	*
	* @author     Ray Guo 
	* @since      Framework 1.1
	*/
	public static String hdrToWhereClause(CategoryItemLineSrchCriteria crit) {

		CategoryItemLineSrchCriteria criteria = (CategoryItemLineSrchCriteria) crit;
		StringBuffer whereClause = new StringBuffer();

		

		/*
		if (criteria.getSrchProgram() != null) {
			whereClause.append(whereClause.length() == 0 ? " WHERE " : " AND ");
			whereClause.append(" SALES_CONTRACT_NO IN ");
			whereClause.append(" (SELECT SALES_CONTRACT_NO FROM T_SALES_CONTRACT_DTL");
			if (criteria.getSrchProgram() != null) {
				whereClause.append(" WHERE PROGRAM ='" + criteria.getSrchProgram().toUpperCase().trim() + "'");
			}
			whereClause.append(")");
		}
		if (criteria.getSrchSalesContractNoFr() != null) {
			whereClause.append(whereClause.length() == 0 ? "WHERE " : "AND ");
			whereClause.append("SALES_CONTRACT_NO >= '"
				+ criteria.getSrchSalesContractNoFr().toUpperCase().trim() + "' ");
		}
		if (criteria.getSrchSalesContractNoTo() != null) {
			whereClause.append(whereClause.length() == 0 ? "WHERE " : "AND ");
			whereClause.append("SALES_CONTRACT_NO <= '"
				+ criteria.getSrchSalesContractNoTo().toUpperCase().trim() + "' ");
		}
		if (criteria.getSrchPoDateFr() != null) {
			whereClause.append(whereClause.length() == 0 ? "WHERE " : "AND ");
			whereClause.append(" PO_DATE >= TO_DATE('"
				+ criteria.getSrchPoDateFr() + "', '"
				+ ProjectConstants.ORACLE_INPUT_DATE_FORMAT + "') ");
		}
		if (criteria.getSrchPoDateTo() != null) {
			whereClause.append(whereClause.length() == 0 ? "WHERE " : "AND ");
			whereClause.append(" PO_DATE <= TO_DATE('"
				+ criteria.getSrchPoDateTo() + "', '"
				+ ProjectConstants.ORACLE_INPUT_DATE_FORMAT + "') ");
		}
		*/

		return whereClause.toString();
	}

}
